# -*- coding: utf-8 -*-
'''
Created on 2013-7-4

@author: yq
'''
from Common.htmlHlep import Find
from Common.tool import tool
from Cms import config
from Cms.plus import  page,user
from Models import  models
import  hashlib,datetime,random,SysFileController
from django.db import transaction


class ArticleCommon:
        
    '''
*****************************公共的******************************
'''

    def Add(self,request,templateId=1):
            contentId=request.POST.get("KeyId","")
            #保存主表
            overdateTime=request.POST.get("OverdateTime","")
            ArticleTypeid=request.POST.get("ArticleType","")
            
            info=models.Article_Content(UserId =user.user().GetUser(request),Click = 0,
                                         IsImage = request.POST.get("FileId","")!="",
                                         SubmitTime =datetime.datetime.now(),CommentNum=0,
                                         TemplateId=models.Article_Template.objects.get(id=templateId)
                                         )
            info.ContentId=contentId
            if overdateTime!="":
                info.OverTime=datetime.datetime.strptime(overdateTime,'%Y-%m-%d')
            Find.UpdateModel(request,info)
            info.ArticleTypeid=models.Article_Type.objects.get(ArticleTypeid=ArticleTypeid)
            return info
    
    def Edit(self,request):
            #保存主表
            contentId=request.POST.get("KeyId","")
            info=models.Article_Content.objects.get(ContentId=contentId)
            if request.POST.get("OverdateTime","")!="":
                info.OverTime=datetime.datetime.strptime(request.POST.get("OverdateTime",""),'%Y-%m-%d')
            info.IsImage = request.POST.get("FileId","")!=""
            Find.UpdateModel(request,info)
            info.ArticleTypeid=models.Article_Type.objects.get(ArticleTypeid=request.POST.get("ArticleType",""))
            return info